import Vue from 'vue'
import VueRouter from 'vue-router'
import indexView from '../views/indexView.vue'
import home from '../views/main/HomeView.vue'
import aboutUs from '../views/main/OuerSelf.vue'
import product from '../views/main/ProductView.vue'
import joinUs from '../views/main/RecruitView.vue'
import notice from '../views/main/NoticeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'indexView',
    component: indexView,
    redirect:'/home',
    children:[
      {
        path:'/home',
        name:'home',
        component:home
      },
      {
        path:'/aboutUs',
        name:'aboutUs',
        component:aboutUs
      },
      {
        path:'/product',
        name:'product',
        component:product
      },
      {
        path:'/joinUs',
        name:'joinUs',
        component:joinUs
      },
      {
        path:'/notice',
        name:'notice',
        component:notice
      }
    ]
  },
]
// 修改导航重复问题
// 1.1获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
// 1.2修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const router = new VueRouter({
  // mode:'hash',
  routes
})
// 跳转后返回顶部
router.afterEach(() => {
  window.scrollTo(0,0);
})
export default router
